'use strict';
const ms = require('ms');
const path = require("path");

module.exports = appInfo => {
    
  const config = exports = {};
  
  config.imgSrc = "static/upload/img/";

  config.baseDir = __dirname.replace("config","");
  
  config.static = {
    dir:path.join(appInfo.baseDir, 'app/static'),
    prefix: '/static/'
  }
 
  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1529338668224_3751';

  // add your config here
  config.middleware = [
    'errorHandler',
    'authSession',
  ];

  config.authSession={
    match: '/api',
  };

  config.multipart = {
    fileSize: '50mb',
    whitelist: [
      '.jpg', 
      '.jpeg', // image/jpeg
      '.png', // image/png, image/x-png
      '.gif', // image/gif
    ],
  };

  config.errorHandler = {
    match: '/api',
  };

  config.security = {
    csrf: {
      ignore:"/user",
      bodyName: '_csrf',
      headerName: 'x-csrf-token', // 通过 header 传递 CSRF token 的默认字段为 x-csrf-token
    },
  };

  config.passportGithub = {
    key: 'EGG_SESS123',
    secret: appInfo.name + '_1529338668224_3751',
    // callbackURL: '/passport/github/callback',
    // proxy: false,
  };

  config.session = {
    key: 'EGG_SESS123',
    maxAge: 24 * 3600 * 1000, // 1 天
    httpOnly: true,
    encrypt: true,
  };

  config.mysql = {
    // 单数据库信息配置
    client: {
      // host
      host: '111.230.242.39',
      // host:"127.0.0.1",
      // 端口号
      port: '3306',
      // 用户名
      user: 'root',
      // 密码
      password: 'qwe456',
      // 数据库名
      database: 'bei',
      charset : 'utf8mb4'
    },
    // 是否加载到 app 上，默认开启
    app: true,
    // 是否加载到 agent 上，默认关闭
    agent: false,
    charset : 'utf8mb4'
  };

  config.jwt = {
    secret: '123456',
    lifeTime: ms('2h'), // 2小时
  };
  return config;
};

